import { hyh_authorize, hyh_hasPermission, hyh_openSetting, hyh_showModal } from '@/utils/hyh_uni_utils';

export const handlePromisify = async (promisify_msg, promisify) => {
	let hasPermission = await hyh_hasPermission(promisify)
	if (!hasPermission) {
		hasPermission = await hyh_authorize(promisify).catch(() => false)
		console.log(hasPermission);
		if (!hasPermission) {
			const flag = await hyh_showModal({
				title: '提示',
				content: `我们需要您的${promisify_msg}权限`
			})
			if (flag) {
				await hyh_openSetting()
				hasPermission = await hyh_hasPermission(promisify)
				if (!hasPermission) throw new Error('获取权限失败')
			} else throw new Error('获取权限失败')
		}
	}
}